/**
* @file snapshot.cpp
*
* Copyright (c) Huawei Technologies Co., Ltd. 2025. All Rights reserved.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/

#include "runtime/acl_rt_impl.h"
#include "runtime/rts/rts_snapshot.h"
#include "common/log_inner.h"
#include "error_codes_inner.h"

aclError aclrtSnapShotProcessLockImpl()
{
    ACL_LOG_INFO("start to execute aclrtSnapShotProcessLock");
    const rtError_t rtErr = rtSnapShotProcessLock();
    if (rtErr != RT_ERROR_NONE) {
        ACL_LOG_CALL_ERROR("execute SnapShotProcessLock failed, runtime result = %d", static_cast<int32_t>(rtErr));
        return ACL_GET_ERRCODE_RTS(rtErr);
    }

    ACL_LOG_INFO("successfully execute aclrtSnapShotProcessLock");
    return ACL_SUCCESS;
}

aclError aclrtSnapShotProcessUnlockImpl()
{
    ACL_LOG_INFO("start to execute aclrtSnapShotProcessUnlock");
    const rtError_t rtErr = rtSnapShotProcessUnlock();
    if (rtErr != RT_ERROR_NONE) {
        ACL_LOG_CALL_ERROR("execute SnapShotProcessUnLock failed, runtime result = %d", static_cast<int32_t>(rtErr));
        return ACL_GET_ERRCODE_RTS(rtErr);
    }

    ACL_LOG_INFO("successfully execute aclrtSnapShotProcessUnlock");
    return ACL_SUCCESS;
}

aclError aclrtSnapShotProcessBackupImpl()
{
    ACL_LOG_INFO("start to execute aclrtSnapShotProcessBackup");
    const rtError_t rtErr = rtSnapShotProcessBackup();
    if (rtErr != RT_ERROR_NONE) {
        ACL_LOG_CALL_ERROR("execute SnapShotProcessBackup failed, runtime result = %d", static_cast<int32_t>(rtErr));
        return ACL_GET_ERRCODE_RTS(rtErr);
    }

    ACL_LOG_INFO("successfully execute aclrtSnapShotProcessBackup");
    return ACL_SUCCESS;
}

aclError aclrtSnapShotProcessRestoreImpl()
{
    ACL_LOG_INFO("start to execute aclrtSnapShotProcessRestore");
    const rtError_t rtErr = rtSnapShotProcessRestore();
    if (rtErr != RT_ERROR_NONE) {
        ACL_LOG_CALL_ERROR("execute SnapShotProcessRestore failed, runtime result = %d", static_cast<int32_t>(rtErr));
        return ACL_GET_ERRCODE_RTS(rtErr);
    }

    ACL_LOG_INFO("successfully execute aclrtSnapShotProcessRestore");
    return ACL_SUCCESS;
}

aclError aclrtSnapShotProcessGetStateImpl(aclrtProcessState *state)
{
    ACL_LOG_INFO("start to execute aclrtSnapShotProcessRestore");
    ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(state);
    rtProcessState rtState;
    const rtError_t rtErr = rtSnapShotProcessGetState(&rtState);
    *state = static_cast<aclrtProcessState>(rtState);
    if (rtErr != RT_ERROR_NONE) {
        ACL_LOG_CALL_ERROR("execute SnapShotProcessGetState failed, runtime result = %d", static_cast<int32_t>(rtErr));
        return ACL_GET_ERRCODE_RTS(rtErr);
    }

    ACL_LOG_INFO("successfully execute aclrtSnapShotProcessRestore, state is %d.", static_cast<int32_t>(*state));
    return ACL_SUCCESS;
}

